<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>BLOBkit Samples</title>
		<link rel='stylesheet' type='text/css' href='../tvb.css' />
		<script type="text/javascript" src='../tvb-min.js'></script>
	</head>
	<body>
		<script type="text/javascript">
			TVB.widget.titleBar.setTitle("Podcast Manager - getFeedContentByID()");
			TVB.widget.titleBar.setIcon("http://www.blobforge.com/static/lib/resources/ibk.png");
			TVB.widget.titleBar.render();
		</script>
		
		<div id='content'>
			<p>Please select a feed to display its contents:</p>
			<ul id='feed_list'></ul>
		</div>

		<script type="text/javascript">
			
			/*
			 * showInfo(id) displays the information associated to current feed ID
			 */
			var showInfo = function(id) {
				try {
					var con = document.getElementById('content');
					
					// Verify the existence of the feedID
					if (TVB.podcast.feedExists(id) == false) {
						// ID not found
						con.innerHTML = "<p>Error: feed not found.</p>";
					} else {
						
						// Fetch data for given feedID
						var data = TVB.podcast.getFeedContentByID(id);
						var html = "<table border=1>";
						html += "<tr>";
						html += "<td>ID</td>";
						html += "<td>Title</td>";
						html += "<td>Status</td>";
						html += "<td>Percentage</td>";
						html += "</tr>";
						for (var i in data) {
							html += "<tr>";
							html += "<td>" + data[i].ID + "</td>";
							html += "<td>" + data[i].title + "<br />URI: " + TVB.podcast.getUriByID(id, data[i].ID) + "</td>";
							html += "<td>" + data[i].downloadStatus + "</td>";
							html += "<td>" + parseInt(data[i].downloadPercentage) + " %</td>";
							html += "</tr>";
						}
						html += "</table>";
						con.innerHTML = html;
					}		
				} catch (e) {
					TVB.error(e.message);
				}
			}
			
			try {
				// Request ID's list of user's subscribed feeds 
				var id_list = TVB.podcast.getVisibleFeedsID();
				
				// Draw on screen a table containing all feeds ID
				
				if (id_list.length > 0) {
				
					for (var i in id_list) {
						var el = document.createElement('li');
						el.innerHTML = "<a href='#' onclick=\"showInfo('" + id_list[i] + "'); return falsE;\">" + id_list[i] + "</a>";
						document.getElementById('feed_list').appendChild(el);
					}
					
				} else {
					var el = document.createElement('li');
					el.innerHTML = "Please subscribe at least to one feed with Podcast";
					document.getElementById('feed_list').appendChild(el);
				}

			} catch (e) {
				TVB.error(e.message);
			}
		</script>
	</body>
</html>
